#pragma once
#include "Protocol.hpp"
#include <memory>

class NetCal
{
public:
    NetCal()
    {
    }

    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        auto res = Factory::BuildResponseDefault();
        switch (req->Oper())
        {
        case '+':
            res->_result = req->X() + req->Y();
            break;
        case '-':
            res->_result = req->X() - req->Y();
            break;
        case '*':
            res->_result = req->X() * req->Y();
            break;
        case '%':
            if (req->Y() == 0)
            {
                res->_code = 1;
                res->_desc = "mod zero";
            }
            else
                res->_result = req->X() % req->Y();
            break;

        case '/':
            if (req->Y() == 0)
            {
                res->_code = 2;
                res->_desc = "div zero";
            }
            else
                res->_result = req->X() / req->Y();
            break;
        default:
            res->_code = 3;
            res->_desc = "illegal operation";
            break;
        }
        return res;
    }

    ~NetCal()
    {
    }
};